<template>
    <t-dialog :visible.sync="visible"
    :header="header"
    confirmBtn="提交"
    :confirmLoading="confirmLoading"
    :onConfirm="submit"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    placement="center"
    width="60%">
        <div style="height: 65vh; width: 98%">
            <t-form ref="form" :data="formData" :rules="rules" :colon="true">
            <t-row :gutter="[14,25]">
                <t-col :span="6">
                    <t-form-item label="成果名称" name="name">
                        <t-input clearable v-model="formData.name"></t-input>
                    </t-form-item>
                    <t-form-item label="成果类别" name="type">
                        <t-select style="width: 100%" clearable  v-model="formData.type"
                            :options="dict.type.cgzh_ministry_result_type">
                        </t-select>
                    </t-form-item>
                    <t-form-item label="单位名称" name="unitName">
                        <t-input clearable v-model="formData.unitName"></t-input>
                    </t-form-item>
                    <t-form-item label="电子邮箱" name="email">
                        <t-input clearable v-model="formData.email"></t-input>
                    </t-form-item>
                </t-col>
                <t-col :span="6">
                    <t-form-item label="联系地址" name="address">
                        <t-input clearable v-model="formData.address"></t-input>
                    </t-form-item>
                    <t-form-item label="邮编" name="postCode">
                        <t-input clearable v-model="formData.postCode"></t-input>
                    </t-form-item>
                    <t-form-item label="联系人" name="linkman">
                        <t-input clearable v-model="formData.linkman"></t-input>
                    </t-form-item>
                    <t-form-item label="联系电话" name="phone">
                        <t-input clearable v-model="formData.phone"></t-input>
                    </t-form-item>
                </t-col>
                <t-col :span="12">
                    <div></div>
                    <t-form-item name="feature" label="功能与用途">
                      <tiny-mce-editor v-model="formData.feature"></tiny-mce-editor>
                    </t-form-item>
                    <t-form-item name="intro" label="技术简介">
                      <tiny-mce-editor v-model="formData.intro"></tiny-mce-editor>
                    </t-form-item>
                </t-col>
                    
            </t-row>
        </t-form>
        </div>
    </t-dialog>
</template>

<script>
import TinyMceEditor from "@/components/TinyMceEditor/index.vue";

export default {
  name: "road-add",
  dicts: ["cgzh_ministry_result_type"],
  components: {
    TinyMceEditor
  },
  props:{
    objId: {
      type: String,
      default: '',
    },
    header: {
      type: String,
      default: '新增'
    },
    row: {
      type: Object,
      default: () => ({})
    },
    isUpdate: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: true,
      formData: {
        name: '',
        type: '',
        feature: '',
        intro: '',
        unitName: '',
        address: '',
        postcode: '',
        linkman: '',
        phone: '',
        email: ''
      },
      confirmLoading: false,
      rules: {
        name: [
          { required: true, message: "成果名称不能为空" }
        ],
        type: [
          { required: true, message: "成果类别不能为空" }
        ],
        feature: [
          { required: true, message: "功能与用途不能为空" }
        ],
        intro: [
          { required: true, message: "技术简介不能为空" }
        ],
        unitName: [
          { required: true, message: "单位名称不能为空" }
        ],
        address: [
          { required: true, message: "联系地址不能为空" }
        ],
        postCode: [
          { required: true, message: "邮编不能为空" }
        ],
        linkman: [
          { required: true, message: "联系人不能为空" }
        ],
        phone: [
          { required: true, message: "联系电话不能为空" }
        ],
        email: [
          { required: true, message: "电子邮箱不能为空" }
        ]
      },
    }
  },
  created() {
    Object.assign(this.formData, this.row)
  },
  methods: {
    closeDialog() {
      this.$emit("update:visible", false);
    },
    submit() {
      this.confirmLoading = true
      const promise = this.isUpdate ? this.$api.cgzh.ministry.update(this.formData) : this.$api.cgzh.ministry.add(this.formData)
      promise.then(res => {
        this.confirmLoading = false
        this.visible = false
        this.$emit("update:visible", false);
        this.$emit("reload")
      }).catch((e) => {
        this.$message.error(e.toString());
        this.confirmLoading = false
      });
    }
  },
}

</script>

<style scoped>

</style>